package com.tomtop.core.logging;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.tomtop.core.utils.JSONUtils;

/**
 * Aop 访问日志
 * @author lenovo
 *
 */
@Aspect
@Order(1)
@Component
public class ServiceRunTimeAop {

    @Pointcut("within(@org.springframework.stereotype.Service *)")
    public void ServiceRunTime() {
    }

    @Around("ServiceRunTime()")
    public Object recordSysLog(ProceedingJoinPoint point) throws Throwable {

        long starttime=System.currentTimeMillis();
	    try {
	         return point.proceed();
		} finally {
	        String methodName = point.getSignature().getName();
	        String className = point.getTarget().getClass().getName();
	        Object[] param = point.getArgs();
			String params= JSONUtils.toJSONString(param);
		    long runtime = System.currentTimeMillis()-starttime;
		    RunTimeLog.log(runtime, " [方法]:{}.{},[参数]:{}", className, methodName, params);
		}
    }
 
}
